<template>
    <div :class="{'opacity_panel': !showPanel}" class="audit_panel">
        <!--信审操作面板-->
        <h3 class="audit_panel_title">{{$t('audit.auditOperationPanel')}}</h3>
        <!--风险提示start-->
        <!--<div v-if="showPanel" class="audit_panel_module">-->
            <!--<div class="audit_panel_module_title">{{$t('audit.riskHint')}}</div>-->
            <!--<div class="panel_content warning_tips">-->
                <!--<el-row class="tips_row tips_row_title">-->
                    <!--&lt;!&ndash;风险提示码&ndash;&gt;-->
                    <!--<el-col class="tips_code" :span="6">{{$t('audit.riskHintCode')}}</el-col>-->
                    <!--&lt;!&ndash;风险提示类型&ndash;&gt;-->
                    <!--<el-col class="tips_content" :span="6">{{$t('audit.show')}}</el-col>-->
                <!--</el-row>-->
                <!--<el-row v-for="(item, $index) in riskList" :key="$index" class="tips_row">-->
                    <!--<el-col class="tips_code" :span="6">{{ item.code }}</el-col>-->
                    <!--<el-col class="tips_content" :span="18">-->
                        <!--<template v-if="item.remarks && item.remarks.length > 0">-->
                            <!--<template v-for="remark in item.remarks">-->
                                <!--<span class="ml_10" v-if="item.code === 'R001'">{{ remark.userName }}</span>-->
                                <!--<span class="ml_10" v-else-if="item.code === 'R002'">{{ remark.phone }}</span>-->
                                <!--<template v-else-if="item.code === 'R010'">-->
                                    <!--<a class="ml_10" @click="goDetail(remark.userId)"-->
                                       <!--v-if="remark.userName && remark.userId"-->
                                       <!--href="javascript:void(0);">{{ remark.userName }}</a>-->
                                    <!--<span v-if="remark.userName && !remark.userId">{{ remark.userName }}</span>-->
                                <!--</template>-->
                                <!--<template v-else-if="item.code === 'R011'">-->
                                    <!--<a class="ml_10" @click="goDetail(remark.userId)"-->
                                       <!--v-if="remark.userName && remark.userId"-->
                                       <!--href="javascript:void(0);">{{ remark.userName }}<span v-if="remark.companyName">-{{ remark.companyName-->
                                        <!--}}</span></a>-->
                                    <!--<span v-if="remark.userName && !remark.userId">{{ remark.userName }}<span-->
                                            <!--v-if="remark.companyName">-{{ remark.companyName }}</span></span>-->
                                <!--</template>-->
                                <!--<template v-else-if="item.code === 'R012'">-->
                                    <!--<a class="ml_10" @click="goDetail(remark.userId)"-->
                                       <!--v-if="remark.userName && remark.userId"-->
                                       <!--href="javascript:void(0);">{{ remark.userName }}<span-->
                                            <!--v-if="remark.phone">-{{ remark.phone }}</span></a>-->
                                    <!--<span v-if="remark.userName && !remark.userId">{{ remark.userName }}<span-->
                                            <!--v-if="remark.phone">-{{ remark.phone }}</span></span>-->
                                <!--</template>-->
                                <!--&lt;!&ndash;2-18-09-21新增风险提示码R016&ndash;&gt;-->
                                <!--<span class="ml_10" v-if="item.code === 'R016'">{{ remark.new_phone }}</span>-->
                                <!--&lt;!&ndash;END&ndash;&gt;-->
                                <!--<a class="ml_10" @click="goDetail(remark.userId)"-->
                                   <!--v-else-if="remark.userName && remark.userId"-->
                                   <!--href="javascript:void(0);">{{ remark.userName }}<span-->
                                        <!--v-if="remark.companyName">-{{ remark.companyName }}</span></a>-->
                                <!--<span v-else-if="remark.userName && !remark.userId">{{ remark.userName }}<span-->
                                        <!--v-if="remark.companyName">-{{ remark.companyName }}</span></span>-->
                                <!--<span v-else-if="remark.count"></span>-->
                                <!--<span class="ml_10" v-else-if="item.code === 'K162'">{{ remark.msg }}</span>-->
                                <!--<span class="ml_10" v-else-if="item.code === 'K163'">{{ remark.msg }}</span>-->
                                <!--<span class="ml_10" v-else-if="item.code === 'K164'">{{ remark.msg }}</span>-->
                                <!--&lt;!&ndash;2018-09-21新增风险提示码K165&ndash;&gt;-->
                                <!--<span class="ml_10" v-else-if="item.code === 'K165'"></span>-->
                                <!--&lt;!&ndash;END&ndash;&gt;-->
                            <!--</template>-->
                        <!--</template>-->
                        <!--<span v-else-if="item.remarks.length === 0 && (item.code === 'R003' || item.code === 'R006')"></span>-->
                        <!--<span v-else-if="item.remarks.length === 0">&#45;&#45;</span>-->
                    <!--</el-col>-->
                <!--</el-row>-->
            <!--</div>-->
        <!--</div>-->
        <!--风险提示end-->

        <!--风险提示2-->
        <div v-if="showPanel" class="audit_panel_module">
            <div class="audit_panel_module_title">{{$t('audit.riskHint')}}</div>
            <div class="panel_content warning_tips">
                <el-row class="tips_row tips_row_title">
                    <!--风险提示代码-->
                    <el-col class="tips_code" :span="10">{{$t('audit.riskHintCode')}}</el-col>
                    <!--展示-->
                    <el-col class="tips_content" :span="14">{{$t('audit.show')}}</el-col>
                </el-row>
                <el-row v-for="(item, $index) in riskTipsTwoNew" :key="$index" class="tips_row">
                    <el-col class="tips_code" :span="10">{{ item.riskCode }}</el-col>
                    <el-col class="tips_content" :span="14">{{ item.remarks }}</el-col>
                </el-row>
            </div>
        </div>
        <!--风险提示2 END-->

        <!--2018-06-05新增专案提示-->
        <!--<div v-if="showPanel" class="audit_panel_module">-->
            <!--<div class="audit_panel_module_title">{{$t('audit.caseTips')}}</div>-->
            <!--<div class="panel_content warning_tips">-->
                <!--<el-row class="tips_row tips_row_title">-->
                    <!--&lt;!&ndash;专案个数&ndash;&gt;-->
                    <!--<el-col class="tips_code" :span="10">{{$t('audit.specialCaseNum')}}</el-col>-->
                    <!--&lt;!&ndash;审核内容&ndash;&gt;-->
                    <!--<el-col class="tips_content" :span="14">{{$t('audit.showDetail')}}</el-col>-->
                <!--</el-row>-->
                <!--<el-row v-for="(item, $index) in caseList" :key="$index" class="tips_row">-->
                    <!--<el-col class="tips_code" :span="10">{{ item.specialCaseCnt }}</el-col>-->
                    <!--<el-col class="tips_content" :span="14">{{ item.hintContent }}</el-col>-->
                <!--</el-row>-->
            <!--</div>-->
        <!--</div>-->
        <!--专案提示END-->
        <!--专案码-->
        <div v-if="showProjectCode" class="audit_panel_module">
            <div class="audit_panel_module_title">{{$t('audit.projectCode')}}</div>
            <div class="panel_content warning_tips">
                <el-row class="tips_row tips_row_title">
                    <!--专案个数-->
                    <el-col class="tips_code" :span="24">【TYPE-DH】</el-col>
                </el-row>
            </div>
        </div>
        <!--专案码-->
        <!--照会注记start-->
        <div v-if="showPanel" class="audit_panel_module">
            <div class="audit_panel_module_title">{{$t('audit.xsNote')}}</div>
            <div class="panel_content tv_records">
                <el-form :model="tvRecordsForm" :rules="tvRules" ref="tvForm" label-position="top">
                    <el-form-item label="TV1" prop="tv1">
                        <el-select v-model="tvRecordsForm.tv1" :placeholder="$t('verify.plsChoose')">
                            <el-option v-for="opt in tvOptList.tv1"
                                       :label="$root.local === 'zhCN' ? (opt.tvCode + ' ' + opt.tvReasonZh) : (opt.tvCode + ' ' + opt.tvReasonEnglish)"
                                       :key="opt.id" :value="opt.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="TV2" prop="tv2">
                        <el-select v-model="tvRecordsForm.tv2" :placeholder="$t('verify.plsChoose')">
                            <el-option v-for="opt in tvOptList.tv2"
                                       :label="$root.local === 'zhCN' ? (opt.tvCode + ' ' +opt.tvReasonZh) : (opt.tvCode + ' ' + opt.tvReasonEnglish)"
                                       :key="opt.id" :value="opt.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="TV3" prop="tv3">
                        <el-select v-model="tvRecordsForm.tv3" :placeholder="$t('verify.plsChoose')">
                            <el-option v-for="opt in tvOptList.tv3"
                                       :label="$root.local === 'zhCN' ? (opt.tvCode + ' ' + opt.tvReasonZh) : (opt.tvCode + ' ' + opt.tvReasonEnglish)"
                                       :key="opt.id" :value="opt.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item :label="$t('audit.abnormal')" prop="g" v-if="tvRecordsForm.tv3===25">
                        <el-select v-model="tvRecordsForm.g" :placeholder="$t('verify.plsChoose')">
                            <el-option v-for="opt in tvOptList.g"
                                       :label="$root.local === 'zhCN' ? opt.tvReasonZh : opt.tvReasonEnglish" :key="opt.id"
                                       :value="opt.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="tvRemark">
                        <el-input v-model="tvRecordsForm.tvRemark" :rows="4" type="textarea" :placeholder="$t('audit.TvExplanation')" :maxlength="800">TV说明</el-input>
                    </el-form-item>
                    <el-form-item class="form_btn">
                        <el-button
                                :disabled="!tvRecordsForm.tv1 || !tvRecordsForm.tv2 || !tvRecordsForm.tv3||(tvRecordsForm.tv3==23&&!tvRecordsForm.g) || submitNoteDisabled"
                                type="primary" @click="submitNote">{{$t('common.submit')}}</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!--照会注记end-->

        <!--OC码start-->
        <div v-if="showPanel" class="audit_panel_module">
            <div class="audit_panel_module_title">{{$t('audit.OCCode')}}</div>
            <div class="panel_content tv_records">
                <el-form :model="OCForm" label-position="top">
                    <el-form-item>
                        <el-select v-model="OCForm.OCCode">
                            <el-option v-for="(item, $index) in OCList" :key="$index" :value="item.ocCode" :label="$root.local==='zhCN' ? item.ocCodeZh : item.ocCodeEnglish"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item class="form_btn">
                        <el-button :disabled="!OCForm.OCCode || submitOcCodeDisabled" type="primary" @click="submitOcCode">{{$t('common.submit')}}
                        </el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!--OC码end-->

        <!--新增SPC码-->
        <!--<div v-if="showPanel" class="audit_panel_module">-->
            <!--<div class="audit_panel_module_title">{{$t('audit.spcCode')}}</div>-->
            <!--<div class="panel_content tv_records">-->
                <!--<el-form :model="SPCForm" label-position="top">-->
                    <!--<el-form-item>-->
                        <!--<el-select v-model="SPCForm.spcCode">-->
                            <!--<el-option v-for="(item, $index) in SPCList"-->
                                       <!--v-if="item.dictCode !== 'SPC018' && item.dictCode !== 'SPC019'" :key="$index"-->
                                       <!--:value="item.dictCode"-->
                                       <!--:label="item.dictCode + '-' + item.dictCodeName"></el-option>-->
                            <!--<el-option v-for="(item, $index) in SPCList"-->
                                       <!--v-if="item.dictCode === 'SPC018' || item.dictCode === 'SPC019'" :key="$index"-->
                                       <!--:value="item.dictCode" :label="item.dictCode"></el-option>-->
                        <!--</el-select>-->
                    <!--</el-form-item>-->
                    <!--<el-form-item :label="$t('audit.spcRemark')">-->
                        <!--<el-input v-model="SPCForm.remark" type="textarea" :rows="4" :maxlength="200"></el-input>-->
                    <!--</el-form-item>-->
                    <!--<el-form-item class="form_btn">-->
                        <!--<el-button :disabled="!SPCForm.spcCode" type="primary" @click="addSpcCodeRemark">{{ $t('common.submit') }}</el-button>-->
                    <!--</el-form-item>-->
                <!--</el-form>-->
            <!--</div>-->
        <!--</div>-->
        <!--SPC码END-->

        <!--信审备注start-->
        <div v-if="showPanel" class="audit_panel_module">
            <div class="audit_panel_module_title">{{$t('audit.auditRemark')}}</div>
            <div class="panel_content tv_records">
                <el-form :model="auditRemarkForm" label-position="top">
                    <el-form-item prop="auditRemark">
                        <el-input v-model="auditRemarkForm.auditRemark" :rows="4" type="textarea" :maxlength="800"></el-input>
                    </el-form-item>
                    <el-form-item class="form_btn">
                        <el-button :disabled="!auditRemarkForm.auditRemark || submitOrderRemarkDisabled" type="primary"
                                   @click="submitOrderRemark">{{$t('common.submit')}}</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!--信审备注end-->

        <!--信审结论start-->
        <div v-if="showPanel && (orderStatus !== -1 && orderStatus !== 5)" class="audit_panel_module">
            <div class="audit_panel_module_title">{{$t('audit.auditConclusion')}}</div>
            <!--初审操作start-->
            <div v-if="orderStatus === 1 || orderStatus === 0" class="panel_content tv_records">
                <el-form :rules="formRules" ref="auditConclusionForm" :model="auditConclusionForm" label-position="top">
                    <el-form-item>
                        <el-radio-group @change="conclusionChange" style="width: 100%;" v-model="auditConclusionForm.conclusion" :disabled="!firstAuditAuthor">
                            <el-row class="conclusion_radio">
                                <el-col :span="12">
                                    <el-radio label="AUDIT_SUCCESS">{{$t('common.pass')}}</el-radio>
                                </el-col>
                                <el-col :span="12">
                                    <el-radio label="AUDIT_CHECK">{{$t('common.refuse')}}</el-radio>
                                </el-col>
                            </el-row>
                        </el-radio-group>
                    </el-form-item>
                    <!-- label="原因1"-->
                    <el-form-item prop="reason1" :label="$t('common.reason') + ' ' + '1'">
                        <el-select v-model="auditConclusionForm.reason1" :placeholder="$t('verify.plsChoose')">
                            <el-option
                                    v-for="reason in reasonList"
                                    :disabled="reason.code === auditConclusionForm.reason2 || reason.code === auditConclusionForm.reason3"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item v-if="auditConclusionForm.reason1 === 'O02'" prop="reason1Remark">
                        <el-input v-model="auditConclusionForm.reason1Remark" type="text" :placeholder="$t('verify.plsInput')"></el-input>
                    </el-form-item>
                    <!--label="原因2" -->
                    <el-form-item prop="reason2" :label="$t('common.reason') + ' ' + '2'">
                        <el-select v-model="auditConclusionForm.reason2" :placeholder="$t('verify.plsChoose')" :disabled="auditConclusionForm.conclusion === 'AUDIT_SUCCESS'">
                            <el-option
                                    v-for="reason in reasonList"
                                    :disabled="reason.code === auditConclusionForm.reason1 || reason.code === auditConclusionForm.reason3"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item v-if="auditConclusionForm.reason2 === 'O02'" prop="reason2Remark">
                        <el-input v-model="auditConclusionForm.reason2Remark" type="text" :placeholder="$t('verify.plsInput')"></el-input>
                    </el-form-item>
                    <!-- label="原因3"-->
                    <el-form-item prop="reason3" :label="$t('common.reason') + ' ' + '3'">
                        <el-select v-model="auditConclusionForm.reason3" :placeholder="$t('verify.plsChoose')" :disabled="auditConclusionForm.conclusion === 'AUDIT_SUCCESS'">
                            <el-option
                                    v-for="reason in reasonList"
                                    :disabled="reason.code === auditConclusionForm.reason2 || reason.code === auditConclusionForm.reason1"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item v-if="auditConclusionForm.reason3 === 'O02'" prop="reason3Remark">
                        <el-input v-model="auditConclusionForm.reason3Remark" type="text" :placeholder="$t('verify.plsInput')"></el-input>
                    </el-form-item>
                    <el-form-item class="form_btn">
                        <el-button
                                :disabled="disableFirstAuditBtn"
                                @click="auditFirstSubmit" type="primary">{{$t('common.submit')}}</el-button>
                    </el-form-item>
                </el-form>
            </div><!--初审操作end-->
            <!--终审操作start-->
            <div v-if="orderStatus === 2 || orderStatus === 4" class="panel_content">
                <el-form :rules="formRules" ref="lastAuditForm" :model="lastAuditForm" label-position="top">
                    <el-form-item>
                        <el-radio-group @change="conclusionChange" style="width: 100%;" v-model="lastAuditForm.status" :disabled="!lastAuditAuthor">
                            <el-row class="conclusion_radio">
                                <el-col :span="12">
                                    <el-radio label="LAST_AUDIT_SUCCESS">{{$t('common.pass')}}</el-radio>
                                </el-col>
                                <el-col :span="12">
                                    <el-radio label="BORROW_AUDIT">{{$t('common.goBack')}}</el-radio>
                                </el-col>
                            </el-row>
                        </el-radio-group>
                    </el-form-item>
                    <!-- label="初审意见"-->
                    <el-form-item :label="$t('audit.firstAuditorOpinion')">
                        <el-select v-model="lastAuditForm.firstAudit" disabled :placeholder="$t('verify.plsChoose')">
                            <el-option
                                    v-for="reason in cacheReasonList.pass"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- label="回退意见"-->
                    <el-form-item prop="remark" :label="$t('audit.goBackOpinion')">
                        <el-input v-model="lastAuditForm.remark"
                                  :disabled="lastAuditForm.status === 'LAST_AUDIT_SUCCESS' || lastAuditForm.status === ''"
                                  type="textarea" :rows="4" :maxlength="500">
                        </el-input>
                    </el-form-item>
                    <el-form-item class="form_btn">
                        <el-button
                                :disabled="disableLastAuditBtn"
                                @click="lastAuditSubmit" type="primary">{{$t('common.submit')}}</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!--终审操作end-->
            <!--复核操作start-->
            <div v-if="orderStatus === 3" class="panel_content">
                <el-form :rules="formRules" ref="recheckForm" :model="recheckForm" label-position="top">
                    <el-form-item>
                        <el-radio-group @change="conclusionChange" style="width: 100%;" v-model="recheckForm.status">
                            <el-row class="conclusion_radio">
                                <el-col :span="12">
                                    <el-radio label="AUDIT_REFUSE">{{$t('audit.recheckAudit')}}</el-radio>
                                </el-col>
                                <el-col :span="12">
                                    <el-radio label="BORROW_AUDIT">{{$t('common.goBack')}}</el-radio>
                                </el-col>
                            </el-row>
                        </el-radio-group>
                    </el-form-item>
                    <!-- label="初审意见"-->
                    <el-form-item :label="$t('audit.firstAuditorOpinion')">
                        <el-select class="recheck_select" v-model="recheckForm.reason1" disabled :placeholder="$t('verify.plsChoose')">
                            <el-option
                                    v-for="reason in cacheReasonList.reject"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                        <el-select class="recheck_select" v-model="recheckForm.reason2" disabled :placeholder="$t('verify.plsChoose')">
                            <el-option
                                    v-for="reason in cacheReasonList.reject"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                        <el-select class="recheck_select" v-model="recheckForm.reason3" disabled :placeholder="$t('verify.plsChoose')">
                            <el-option
                                    v-for="reason in cacheReasonList.reject"
                                    :label="reason.code + ' ' + ($root.local === 'zhCN' ? reason.text : reason.english)"
                                    :key="reason.code"
                                    :value="reason.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- label="回退意见"-->
                    <el-form-item prop="remark" :label="$t('audit.goBackOpinion')">
                        <el-input v-model="recheckForm.remark"
                                  :disabled="recheckForm.status === 'AUDIT_REFUSE' || recheckForm.status === ''"
                                  type="textarea" :rows="4" :maxlength="500">{{$t('audit.goBackOpinion')}}
                        </el-input>
                    </el-form-item>
                    <el-form-item class="form_btn">
                        <el-button @click="recheckSubmit"
                                   :disabled="disableRecheckAuditBtn"
                                   type="primary">{{$t('common.submit')}}</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!--复核操作end-->
        </div>
        <!--信审结论end-->

        <div v-if="showMask" class="panel_mask"></div><!--遮罩层-->
        <!--<div class="panel_mask"></div>-->
    </div>
</template>

<script>
import EventBus from '@/libs/event-bus';

    export default {
        name: 'auditPanel',
        props: {
            showPanel: {
                type: Boolean,
                default: true
            },
        },
        data() {
            return {
                orderId: '',
                userId: '',
                userType: '',
                tvRecordsForm: {
                    tv1: '',
                    tv2: '',
                    tv3: '',
                    tvRemark: '',
                    g: ''
                },
                auditRemarkForm: {
                    auditRemark: ''
                },
                auditConclusionForm: {
                    conclusion: '',
                    reason1: '',
                    reason2: '',
                    reason3: '',
                    reason1Remark: '',
                    reason2Remark: '',
                    reason3Remark: '',
                },
                tvOptList: {
                    tv1: [],
                    tv2: [],
                    tv3: [],
                    g: [],
                },
                reasonList: [],
                cacheReasonList: {
                    reject: [],
                    pass: []
                },
                formRules: {
                    reason1: [],
                    reason2: [],
                    reason3: [],
                    remark: []
                },
                orderStatus: -1, // 订单状态 0：待分配 1：初审已分配 2：终审已分配 3: 复核'
                lastAuditForm: {
                    firstAudit: 'A00',
                    status: '',
                    type: 2,
                    remark: ''
                }, // 终审表单
                recheckForm: {
                    reason1: '',
                    reason2: '',
                    reason3: '',
                    status: '',
                    remark: ''
                }, // 复核表单
                rejectReason: [], // 初审信审结论
                showMask: false,
                tvRules: {
                    tv1: [],
                    tv2: [],
                    tv3: [],
                    tvRemark: []
                },
                riskAllList: [],
                riskList: [], // 风险提示列表
                caseList: [], // 专案提示列表
                OCForm: {
                    OCCode: ''
                },
                OCList: [],
                submitNoteDisabled: false, // 照会注记提交按钮
                submitOcCodeDisabled: false, // OC码提交按钮
                submitOrderRemarkDisabled: false, // 订单备注提交按钮
                auditFirstSubmitDisabled: false, // 初审提交按钮
                lastAuditSubmitDisabled: false, // 终审提交按钮
                recheckSubmitDisabled: false, // 复核提交按钮
                SPCForm: {
                    remark: '',
                    spcCode: '',
                },
                SPCList: [],
                riskTipsTwo: [],
                riskTipsTwoNew: [],
                showProjectCode: false,
                accountModifying: true, // 收款账户是否处于修改中
                orderAccount: '', // 当前订单的收款账户
            };
        },
        computed: {
            firstAuditAuthor() {
                // 信审初审结论按钮
                return this.$store.getters.checkUserAuthority('details.trail.conclusion');
            },
            lastAuditAuthor() {
                // 信审终审结论按钮
                return this.$store.getters.checkUserAuthority('details.final.conclusion');
            },
            // 禁用初审按钮
            disableFirstAuditBtn() {
                // !auditConclusionForm.reason1 || (auditConclusionForm.reason1 == 'O02' && !auditConclusionForm.reason1Remark) || (auditConclusionForm.reason2 == 'O02' && !auditConclusionForm.reason2Remark) || (auditConclusionForm.reason3 == 'O02' && !auditConclusionForm.reason3Remark) || auditFirstSubmitDisabled
                const { reason1, reason1Remark, reason2, reason2Remark, reason3, reason3Remark, conclusion } = this.auditConclusionForm;
                const { auditFirstSubmitDisabled, accountModifying } = this;
                return !reason1 || (reason1 === 'O02' && !reason1Remark) || (reason2 === 'O02' && !reason2Remark) || (reason3 === 'O02' && !reason3Remark) || auditFirstSubmitDisabled || (conclusion === 'AUDIT_SUCCESS' && accountModifying);
            },
            // 禁用终审按钮
            disableLastAuditBtn() {
                // !lastAuditForm.status || (lastAuditForm.status === 'BORROW_AUDIT' && !lastAuditForm.remark) || lastAuditSubmitDisabled
                const { status, remark } = this.lastAuditForm;
                const { lastAuditSubmitDisabled } = this;
                return !status || (status === 'BORROW_AUDIT' && !remark) || lastAuditSubmitDisabled;
            },
            // 禁用复核按钮
            disableRecheckAuditBtn() {
                // !recheckForm.status || (recheckForm.status === 'BORROW_AUDIT' && !recheckForm.remark) || recheckSubmitDisabled
                const { status, remark } = this.recheckForm;
                const { recheckSubmitDisabled } = this;
                return !status || (status === 'BORROW_AUDIT' && !remark) || recheckSubmitDisabled;
            },
        },
        watch: {
            'tvRecordsForm.tv1' : function (val) {
                if (val + '' === '1' && !this.tvRecordsForm.tv2 && !this.tvRecordsForm.tv3) {
                    this.tvRecordsForm.tv2 = 13;
                    this.tvRecordsForm.tv3 = 17;
                }
            },
            'tvRecordsForm.tv3' : function (val) {
                if ((val + '' === '19' || val + '' === '20') && !this.tvRecordsForm.tv2) {
                    this.tvRecordsForm.tv2 = 24;
                }
            },
            'auditConclusionForm.conclusion' : function (val) {
                if (val === 'AUDIT_SUCCESS') {
                    this.$nextTick(() => {
                        this.auditConclusionForm.reason1 = 'A00';
                    })
                }
            }
        },
        methods: {
            queryRollbackOrder() {
                this.$api.audit.queryRollbackOrder({orderId: this.orderId}).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.showProjectCode = data.mark === '0' ? true : false; // mark:0-是电核回退订单 mark:1-不是电核回退订单
                    }
                });
            },
            // 获取照会记录选项
            tvReasonCode() {
                this.$api.audit.tvReasonCode().then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.tvOptList.tv1 = data.tv1;
                        this.tvOptList.tv2 = data.tv2;
                        this.tvOptList.tv3 = data.tv3;
                        this.tvOptList.g = data.g;
                    }
                });
            },
//      提交照会注记
            submitNote() {
                this.submitNoteDisabled = true;
                const params = {
                    orderId: this.orderId,
                    userId: this.userId,
                    tvRemark: this.tvRecordsForm.tvRemark.trim(),
                    tv1: this.tvRecordsForm.tv1,
                    tv2: this.tvRecordsForm.tv2,
                    tv3: this.tvRecordsForm.tv3,
                    g: this.tvRecordsForm.g,
                };
                this.$api.audit.addTvRemark(params).then((res) => {
                    this.submitNoteDisabled = false;
                    const {status, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.$message.success(this.$t('common.successfulOperation'));
//                        if (this.$refs.tvForm) {
//                            this.$refs.tvForm.resetFields();
//                        }
                        this.$emit('updateTable', 'tvRecords');
                    }
                });
            },
            // 查询信审结论
            getReasonList() {
                this.$api.audit.rejectCode({orderId: this.orderId}).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.cacheReasonList.reject = data.rejectCode;
                        this.cacheReasonList.pass = data.passCode;
                        if (data.riskCode && data.riskCode instanceof Array) {
                            data.riskCode.forEach((item) => {
                                item.remarks = [];
                                this.riskAllList.push(item);
                            });
                        }
                        this.getOrderNewRisk();
                        // 获取订单状态
                        this.getOrderStatus();
                    }
                });
            },
            conclusionChange(val) {
                if (val === 'AUDIT_SUCCESS') {
                    // 初审通过
                    this.reasonList = this.cacheReasonList.pass;
                } else if (val === 'AUDIT_CHECK') {
                    // 初审拒绝，并进入复核
                    this.reasonList = this.cacheReasonList.reject;
                } else if (val === 'LAST_AUDIT_SUCCESS') {
                    // 终审通过，重置回退意见
                    this.$refs.lastAuditForm.resetFields();
                } else if (val === 'AUDIT_REFUSE') {
                    // 复核通过，重置回退意见
                    this.$refs.recheckForm.resetFields();
                }
                if (this.orderStatus === 1) {
                    // 改变初审状态，重置原因选项
                    this.$refs.auditConclusionForm.resetFields();
                }
            },
            getOrderStatus() {
                // 查询订单状态
                this.$api.audit.getOrderAuditBaseInfo({orderId: this.orderId}).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        // disStatus 0：待分配 1：初审已分配 2：终审已分配'
                        // rcaStatus PRE_ADMITTANCE 待准入  ADMITTANCE_SUCCESS 准入成功  AUTO_AUDIT_SUCCESS 自核通过 ADMITTANCE_REFUSE 准入失败
                        // status 待审核 BORROW_AUDIT,初审通过 AUDIT_SUCCESS,复核状态：AUDIT_CHECK,终审通过 LAST_AUDIT_SUCCESS,信审拒绝 AUDIT_REFUSE
                        const orderStatus = data.auditOrder;
                        if (orderStatus.rcaStatus === 'ADMITTANCE_REFUSE') {
                            // 准入失败
                            this.orderStatus = -1;
                        } else if (orderStatus.status === 'AUDIT_CHECK') {
                            // 复核状态
                            this.orderStatus = 3;
                            this.getConclusion();
                        } else if (orderStatus.disStatus === 0) {
                            // 待分配
                            this.orderStatus = 0;
                            this.showMask = true;
                        } else if (orderStatus.disStatus === 1 && orderStatus.status === 'BORROW_AUDIT') {
                            // 初审
                            this.orderStatus = 1;
                            this.getConclusion();
                            // } else if (orderStatus.disStatus === 2 && orderStatus.status === 'AUDIT_SUCCESS') {
                        } else if (orderStatus.status === 'AUDIT_SUCCESS') { // 临时处权限处理
                            // 终审
                            this.orderStatus = 2;
                            this.getConclusion();
                        } else if (orderStatus.status === 'LAST_AUDIT_SUCCESS') {
                            // 终审通过
                            this.orderStatus = 4;
                            this.showMask = true;
                            this.getConclusion();
                        } else if (orderStatus.status === 'AUDIT_REFUSE') {
                            // 信审拒绝
                            this.orderStatus = 5;
                            this.getConclusion();
                        }
                        // if ([1, 2, 3].includes(this.orderStatus)) {
                        //     // 订单处于信审中状态
                        //     this.$emit('isAuditing', true);
                        // }
                    }
                });
            },
            // 查询信审结论、信审备注、风险提示
            getConclusion() {
                this.$api.audit.getOrderSuggestion({orderId: this.orderId}).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        if (this.orderStatus === 3) {
                            // 复核
                            this.rejectReason = data.rejectReason || [];
                            if (this.rejectReason[0]) {
                                this.recheckForm.reason1 = this.rejectReason[0].text;
                            }
                            if (this.rejectReason[1]) {
                                this.recheckForm.reason2 = this.rejectReason[1].text;
                            }
                            if (this.rejectReason[2]) {
                                this.recheckForm.reason3 = this.rejectReason[2].text;
                            }
                        }
                        if (data.risks && data.risks instanceof Array) {
                            this.riskAllList.forEach((risk) => {
                                data.risks.forEach((item) => {
                                    if (risk.code === item.policyNumber && item.remarks) {
                                        try {
                                            let riskAll = null;
                                            let hasRisk = false;
                                            this.riskList.forEach((riskItem) => {
                                                if (riskItem.code === risk.code) {
                                                    hasRisk = true;
                                                    riskAll = riskItem;
                                                }
                                            });
                                            if (!hasRisk) {
                                                riskAll = Object.assign({}, risk);
                                            }
                                            if (item.remarks.indexOf('"[') === 0 && item.remarks.indexOf(']"') > -1) {
                                                item.remarks = item.remarks.substr(1, item.remarks.length - 2);
                                            }
                                            if (item.remarks.indexOf('\\') > -1) {
                                                item.remarks = item.remarks.replace(/\\/g, '');
                                            }
                                            const marks = JSON.parse(item.remarks);
                                            if (marks instanceof Array) {
                                                marks.forEach((mark) => {
                                                    riskAll.remarks.push(mark);
                                                });
                                            } else if (typeof marks === 'object') {
                                                riskAll.remarks.push(JSON.parse(item.remarks));
                                            }
                                            if (!hasRisk) {
                                                this.riskList.push(riskAll);
                                            }
                                        } catch (e) {
                                            // eslint-disable-next-line
                                            console.log(e);
                                            // eslint-disable-next-line
                                            console.log(item);
                                        }
                                    } else if (risk.code === item.policyNumber && item.remarks === '') {
                                        this.riskList.push(Object.assign({}, risk));
                                    }
                                });
                            });
                        }
                        // console.log(this.riskList);
                    }
                });
            },
            // 初审提交
            auditFirstSubmit() {
                this.$refs.auditConclusionForm.validate((val) => {
                    if (val) {
                        this.auditFirstSubmitDisabled = true;
                        const form = this.auditConclusionForm;
                        const params = {
                            userId: this.userId,
                            orderId: this.orderId,
                            status: form.conclusion,
                            rejectReasons: [],
                            remark: '',
                            account: this.orderAccount,
                        };
                        this.reasonList.forEach((reason) => {
                            if (reason.code === form.reason1) {
                                params.rejectReasons.push({
                                    rejectReasonName: 'REJECT_REASON_ONE',
                                    rejectReasonValue: reason.code
                                });
                                params.remark = (form.reason1 === 'O02') ? this.auditConclusionForm.reason1Remark : '';
                            } else if (reason.code === form.reason2) {
                                params.rejectReasons.push({
                                    rejectReasonName: 'REJECT_REASON_TWO',
                                    rejectReasonValue: reason.code
                                });
                                params.remark = (form.reason2 === 'O02') ? this.auditConclusionForm.reason2Remark : '';
                            } else if (reason.code === form.reason3) {
                                params.rejectReasons.push({
                                    rejectReasonName: 'REJECT_REASON_THREE',
                                    rejectReasonValue: reason.code
                                });
                                params.remark = (form.reason3 === 'O02') ? this.auditConclusionForm.reason3Remark : '';
                            }
                        });
                        this.$api.audit.orderCheck(params).then((res) => {
                            this.auditFirstSubmitDisabled = false;
                            const {status, error} = res;
                            if ('1' === status && error === '00000000') {
                                this.$message.success(this.$t('common.successfulOperation'));
                                this.$emit('updateTable', 'auditRecords');
                                window.close();
                                //this.getOrderStatus();
                            }
                        });
                    }
                });
            },
            // 复核信审结论提交
            recheckSubmit() {
                const params = {
                    userId: this.userId,
                    orderId: this.orderId,
                    status: this.recheckForm.status,
                    remark: this.recheckForm.remark.trim()
                };
                if (params.status === 'BORROW_AUDIT' && params.remark === '') {
                    this.$message.error(this.$t('audit.inputBackOpinion'));
                    return false;
                }
                this.recheckSubmitDisabled = true;
                this.$api.audit.orderReCheck(params).then((res) => {
                    this.recheckSubmitDisabled = false;
                    const {status, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.$message.success(this.$t('common.successfulOperation'));
                        this.$emit('updateTable', 'auditRecords');
                        window.close();
                        //this.getOrderStatus();
                    }
                });
                return true;
            },
            // 终审信审结论
            lastAuditSubmit() {
                const params = {
                    userId: this.userId,
                    orderId: this.orderId,
                    status: this.lastAuditForm.status,
                    remark: this.lastAuditForm.remark.trim()
                };
                if (params.status === 'BORROW_AUDIT' && params.remark === '') {
                    this.$message.error(this.$t('audit.inputBackOpinion'));
                    return false;
                }
                this.lastAuditSubmitDisabled = true;
                this.$api.audit.lastOrderCheck(params).then((res) => {
                    this.lastAuditSubmitDisabled = false;
                    const {status, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.$message.success(this.$t('common.successfulOperation'));
                        this.$emit('updateTable', 'auditRecords');
                        window.close();
                        //this.getOrderStatus();
                    }
                });
                return true;
            },
//      增加信审备注
            submitOrderRemark() {
                this.submitOrderRemarkDisabled = true;
                const params = {
                    orderId: this.orderId,
                    remark: this.auditRemarkForm.auditRemark.trim(),
                };
                this.$api.audit.addAuditRemark(params).then((res) => {
                    this.submitOrderRemarkDisabled = false;
                    const {status} = res;
                    if ('1' === status) {
                        this.$message.success(this.$t('common.successfulOperation'));
//                        this.auditRemarkForm = {
//                            auditRemark: '',
//                        };
                        this.$emit('updateTable', 'auditMarks');
                    }
                });
            },
            goDetail(id) {
                this.$openNewBlank(`#/conf/audit/order-manage/audit-detail/${id}`);
            },
            // 获取OC码
            getOcCode() {
                this.$api.audit.getOcCode().then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && '00000000' === error && data instanceof Array) {
                        this.OCList = data;
                    }
                });
            },
            // 提交OC码
            submitOcCode() {
                if (this.OCForm.OCCode) {
                    this.submitOcCodeDisabled = true;
                    const params = {
                        userId: this.userId,
                        orderId: this.orderId,
                        ocCode: this.OCForm.OCCode
                    };
                    this.$api.audit.addOcCodeBean(params).then((res) => {
                        this.submitOcCodeDisabled = false;
                        const {status, error} = res;
                        if ('1' === status && '00000000' === error) {
                            this.$message.success(this.$t('common.successfulOperation'));
                            //this.OCForm.OCCode = '';
                            this.$emit('updateTable', 'OcCode');
                        }
                    });
                }
            },
            querySpecialCase() {
                const params = {
                    userId: this.userId,
                    orderId: this.orderId,
                };
                this.$api.audit.getSpecialCaseMerge(params).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        data.forEach((item) => {
                            this.caseList.push(item);
                        });
                    }
                });
            },
            //  获取SPC码
            getAllSpcCode() {
                const params = {
                    language: this.$storage.getLocal('language')
                };
                this.$api.audit.getAllSpcCode(params).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.SPCList = data;
                    }
                });
            },
            //  提交SPC码
            addSpcCodeRemark() {
                const params = {
                    orderId: this.orderId,
                    spcCode: this.SPCForm.spcCode,
                    remark: this.SPCForm.remark,
                    type: this.orderStatus === 1 ? '1' : (this.orderStatus === 2 ? '2' : '3'),
                };
                this.$api.audit.addSpcCodeRemark(params).then((res) => {
                    const {status, error} = res;
                    if ('1' === status && error === '00000000') {
                        this.$message.success(this.$t('common.successfulOperation'));
                        this.SPCForm = {
                            remark: '',
                            spcCode: '',
                        };
                        this.$emit('updateTable', 'auditSpcCode');
                    }
                });
            },
            //  风险提示2
            getOrderNewRisk() {
                const params = {
                    orderId: this.orderId,
                };
                this.$api.audit.getRiskDatas(params).then((res) => {
                    this.riskTipsTwo = res || [];
                    //  匹配
                    if (res && res instanceof Array) {
                        this.riskAllList.forEach((risk) => {
                            res.forEach((item) => {
                                if (item.riskCode === risk.code) {
                                    this.riskTipsTwoNew.push(item);
                                }
                            })
                        })
                    }
                });
            },
            // 显示选择最近一次提交的表单
            getTvRemarkList() {
                const params = {
                    orderId: this.orderId,
                    userId: this.userId,
                    page: {
                        pageNo: 1,
                        pageSize: 20
                    }
                };
                this.$api.audit.getTvRemarkList(params).then((res) => {
                    const {status, data, error} = res;
                    if ('1' === status && error === '00000000') {
                        if(data.data && data.data.length >= 1) {
                            let item = data.data[0];
                            this.tvRecordsForm.tv1 = item.tv1;
                            this.tvRecordsForm.tv2 = item.tv2;
                            this.tvRecordsForm.tv3 = item.tv3;
                            this.tvRecordsForm.tvRemark = item.tvRemark;
                            this.tvRecordsForm.g = item.g;
                        }
                    }
                });
            },
            // 显示选择最近一次提交的OC码和信审备注
            getDefaultOcCode() {
                const params = {
                    userId: this.userId,
                    page: {
                        pageNo: 1,
                        pageSize: 20
                    }
                };
                this.$api.audit.getOcCodeBean(params).then((res) => {
                    const {status, data} = res;
                    if ('1' === status) {
                        if(data.data && data.data.length >= 1) {
                            let item = data.data[0];
                            this.OCForm.OCCode = item.ocCode;
                        }
                    }
                });
            },
            getDefaultRemarks() {
                const params = {
                    userId: this.userId,
                    page: {
                        pageNo: 1,
                        pageSize: 20
                    }
                };
                this.$api.audit.getAuditRemark(params).then((res) => {
                    const {status, data} = res;
                    if ('1' === status) {
                        if(data.data && data.data.length >= 1) {
                            let item = data.data[0];
                            this.auditRemarkForm.auditRemark = item.remark;
                        }
                    }
                });
            }
        },
        created() {
            if (this.showPanel) {
                // this.getTvList();
                //this.getAllSpcCode();
                if (this.$route.params.orderId) {
                    this.orderId = this.$route.params.orderId;
                    this.getReasonList();
                    //this.getOrderNewRisk();
                    //this.queryRollbackOrder();
                }
                if (this.$route.params.id) {
                    this.userId = this.$route.params.id;
                    this.tvReasonCode();
                    this.getOcCode();
                    //this.querySpecialCase();
                }
                if (this.$route.params.orderId && this.$route.params.id && this.$route.params.isNeedReverse === 'true') {
                    this.getTvRemarkList();
                    this.getDefaultOcCode();
                    this.getDefaultRemarks();
                }
                // console.log(this.$route.params);
                // 监听用户的收款账户是否处于修改中
                EventBus.$on('AccountModifying', (status, account) => {
                    this.accountModifying = status;
                    this.orderAccount = account;
                    // console.log('AccountModifying===>', status, account);
                });
            }
        }
    };
</script>

<style lang="scss" scoped>
    @import "~@/assets/scss/function";

    .audit_panel {
        /*padding: 0 16px;*/
        position: relative;
    }

    .panel_mask {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(255, 255, 255, 0.4);
    }

    .opacity_panel {
        opacity: 0.6;
    }

    .audit_panel_title {
        height: 52px;
        line-height: 52px;
        background-image: url("~@/assets/img/icon_edit.png");
        background-size: 20px 20px;
        background-repeat: no-repeat;
        background-position: left center;
        padding-left: 32px;
        border-bottom: 1px solid #d4d7da;
        margin: 0 16px;
    }

    .audit_panel_module {
        margin: 20px 0 30px;
    }

    .audit_panel_module_title {
        padding-left: 16px;
        border-left: 2px solid $primary;
        margin-bottom: 12px;
    }

    .panel_content {
        padding: 0 16px;
        font-size: 12px;
    }

    /*.warning_tips{*/
    /*font-size: 12px;*/
    /*}*/
    .tips_row {
        margin-top: 12px;
        color: #a6a8aa;
    }

    .tips_row_title {
        color: $colorText;
    }

    .tips_code, .tips_type {
        padding-right: 5px;
    }

    .form_btn {
        text-align: right;
    }

    .conclusion_radio {
        text-align: right;
    }

    .recheck_select {
        margin-bottom: 15px;
    }

    .ml_10 {
        margin-left: 10px;
        &:first-child {
            margin-left: 0;
        }
    }

    .tips_content {
        /*height: 18px;*/
        /*line-height: 18px;*/
        /*overflow: hidden;*/
        /*text-overflow: ellipsis;*/
        /*white-space: nowrap;*/
        white-space: normal;
        word-wrap: break-word;
    }
</style>
